package com.defect.util;



import com.defect.bo.PageDetail;

import java.util.ArrayList;
import java.util.List;

public class pageUtil {
 public static PageDetail getPageInfo(int pageindex, int pagesize, List list){
     if(pageindex<1){pageindex=1;}
     int total = list.size();
     int totalpage=total/pagesize==0?total/pagesize:(total/pagesize)+1;
     if(pageindex>totalpage){
         pageindex = totalpage;
     }
     if (totalpage==0){
         pageindex=1;
     }
     List pagelist = new ArrayList();
     if (pageindex*pagesize>=list.size()){
         if (list.size()>0){
             for (int i = (pageindex-1)*pagesize;i<list.size();i++){
                 System.out.println("i"+i);
                 pagelist.add(list.get(i));
             }
         }
     }else{
         for (int i = (pageindex-1)*pagesize;i<(pageindex-1)*pagesize+pagesize;i++){
             pagelist.add(list.get(i));
         }
     }
     System.out.println(pageindex);
     return new PageDetail(pageindex,pagesize,pagelist.size(),pagelist,total,totalpage);
 }
}
